﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaveEngine.Framework;
using WaveEngine.Framework.Services;

namespace WaveEngine.Extensions.ITasks
{
    public interface ITask
    {
        /// <summary>
        /// Gets the scene.
        /// </summary>
        /// <value>
        /// The scene that owns this task. If it is null it can be considered a global task.
        /// </value>
        Scene Scene { get; }

        /// <summary>
        /// Gets the state of the task.
        /// </summary>
        /// <value>
        /// The state of the task.
        /// </value>
        TaskState TaskState { get; }

        IEnumerable<ITask> ChildTasks { get; }

        /// <summary>
        /// Gets the name of the task.
        /// </summary>
        /// <value>
        /// The name of the task.
        /// </value>
        string TaskName { get; }

        /// <summary>
        /// Occurs when [completed].
        /// </summary>
        event Action Completed;

        /// <summary>
        /// Occurs when [cancelled].
        /// </summary>
        event Action Cancelled;

        /// <summary>
        /// Occurs when [skipped] the task is skipped externally. 
        /// </summary>
        event Action Skipped;

        /// <summary>
        /// It starts the workflow that contains this task. 
        /// </summary>
        void Run();

        /// <summary>
        /// Cancels this instance.
        /// </summary>
        void Cancel();

        /// <summary>
        /// The skip method cancels the current running task if it is skipable and continues with the next task.
        /// If a running task is not skippable but it has children, then it searches its internal running task and tries to skip it recursively.
        /// </summary>
        bool TrySkip();
    };

    public interface ITask<T> : ITask
    {
        T Result { get; }
    }
}



